# -*- coding: utf-8 -*-
# @Time : 2024/5/28 16:21
# @Author : ZH
# @File : 1137.py
# @Software: PyCharm
# class Solution:
#     def tribonacci(self, n: int) -> int:
#         d = [0] * n
#         d[0], d[1], d[2] = 0, 1, 1
#         for i in range(3, n):
#             d[i] = d[i-1] + d[i-2] + d[i-3]
#         return d[n-1]
#

class Solution:
    def tribonacci(self, n: int) -> int:
        f0, f1, f2 = 0, 1, 1
        for i in range(n):
            f0, f1, f2 = f1, f2, f0 + f1 + f2
        return f0


